﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DcsGauges.Gui.Gauges.Interfaces;
using DcsGauges.Shared.DataStructures;
using DcsGauges.Shared.Exceptions;
using DcsGauges.Functional.Math;

namespace DcsGauges.Gui.Gauges.ValueConverters
{
    class LinearConverter : IGaugeValueConverter<float>
    {
        #region Fields  & Properties
        
        private InOutMapping            min;
        private InOutMapping            max;

        private float offset;

        #endregion


        #region Constructors

        public LinearConverter(InOutMapping min, InOutMapping max, float offset = 0.0f)
        {
            this.min            = min;
            this.max            = max;
            this.offset         = offset;
        }

        #endregion


        #region Interface Implementation

        public float Convert(float sourceValue)
        {
            float result = LinAlg.InterpolateFromX(sourceValue, min.InValue, min.OutValue, max.InValue, max.OutValue);
            return result;
        }

        public float ConvertBack(float convertBackValue)
        {
            float result = LinAlg.InterpolateFromY(convertBackValue, min.InValue, min.OutValue, max.InValue, max.OutValue);
            return result;
        }


        public float MinIn
        {
            get { return this.min.InValue; }
        }


        public float MaxIn
        {
            get { return this.max.InValue; }
        }

        #endregion
    }
}
